<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="//res.layui.com/layui/dist/css/layui.css"  media="all">
    <link rel="stylesheet" href="layui/css/layui.css" />
    <script type="text/javascript" src="layui/layui.js" ></script>
    <script type="text/javascript" src="js/jquery-1.12.2.min.js"></script>
</head>
<body>
<form class="layui-form" action="" lay-filter="example">
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="speaker_name" lay-verify="speakerName" placeholder="请输入姓名" autocomplete="off" class="layui-input">
        </div>
    </div>

    <input type="hidden" name="id" lay-verify="id" class="layui-input">

    <div class="layui-form-item">
        <label class="layui-form-label">职位</label>
        <div class="layui-input-block">
            <input type="text" name="speaker_job" lay-verify="speakerJob" placeholder="请输入职位" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">头像地址</label>
        <div class="layui-input-block">
            <input type="text" name="head_img_url" lay-verify="headImgUrl" placeholder="请输入头像地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">简介</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入简介" class="layui-textarea" name="speaker_desc" type=""></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="updateOne">立即修改</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form','layedit','laydate'],function () {
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        findThisSpeaker();

        form.on('submit(updateOne)',function (data) {
            $.ajax({
                type: "post",
                url: "updateSpeaker.do",
                data: data.field,
                dataType: "json",
                success: function (data) {
                    if (data.code == 1) {
                        layer.msg("修改成功!", {
                            icon: 6,
                            time: 500
                        }, function () {
                            var t = parent.layui.table;
                            t.reload('mySpeaker');// 重新加载页面,demo 表示父窗体table标签的id值
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                    } else {
                        layer.msg(data.info);
                    }
                }
            });
            return false;
        });

        function findThisSpeaker() {
            $.ajax({
                type:"get",
                url:"querySpeaker.do"+window.location.search,
                dataType:"json",
                success:function (data) {
                    if (data.code == 1) {
                        form.val('example',data.info);
                    } else {
                        alert(data.info);
                    }
                }
            })
        }

    })

</script>
</body>
</html>